using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InduMall.Core.Models.Mapping
{
    public class OrderProductMap : EntityTypeConfiguration<OrderProduct>
    {
        public OrderProductMap()
        {
            // Primary Key
            this.HasKey(t => t.OrderProductId);

            // Properties
            this.Property(t => t.OrderProductId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Sku)
                .IsRequired()
                .HasMaxLength(60);

            // Table & Column Mappings
            this.ToTable("OrderProduct");
            this.Property(t => t.OrderProductId).HasColumnName("OrderProductId");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.Sku).HasColumnName("Sku");
            this.Property(t => t.Price).HasColumnName("Price");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Discount).HasColumnName("Discount");
            this.Property(t => t.OrderId).HasColumnName("OrderId");

            // Relationships
            this.HasRequired(t => t.Order)
                .WithMany(t => t.OrderProducts)
                .HasForeignKey(d => d.OrderId);
            this.HasRequired(t => t.Product)
                .WithMany(t => t.OrderProducts)
                .HasForeignKey(d => d.ProductId);

        }
    }
}
